lets_plot.bistro.corr.corr_plot¶
-
class
lets_plot.bistro.corr.corr_plot(data, show_legend=True, flip=True, threshold=None)¶ This class is intended to build correlation matrix plot.
Examples
1 2 3 4 5 6 7
import numpy as np from lets_plot import * from lets_plot.bistro.corr import * LetsPlot.setup_html() np.random.seed(42) data = {var: np.random.poisson(size=10) for var in 'abcdef'} corr_plot(data).tiles().build()
1 2 3 4 5 6 7 8 9
import numpy as np from lets_plot import * from lets_plot.bistro.corr import * LetsPlot.setup_html() np.random.seed(42) data = {var: np.random.uniform(size=10) for var in 'abcd'} corr_plot(data).tiles(type='upper', diag=True)\ .labels(type='upper', diag=True, map_size=True, color='black')\ .palette_RdBu().build()
1 2 3 4 5 6 7 8 9
import numpy as np from lets_plot import * from lets_plot.bistro.corr import * LetsPlot.setup_html() np.random.seed(42) data = {var: np.random.normal(size=10) for var in 'abcdef'} corr_plot(data, flip=False, threshold=.4).points().labels()\ .palette_gradient(low='#d73027', mid='#ffffbf', high='#1a9850')\ .build()
-
__init__(data, show_legend=True, flip=True, threshold=None)¶ - Parameters
data (dict or DataFrame) – Correlation will be calculated for each variable pair.
show_legend (bool, default=True) – If True legend is shown.
flip (bool, default=True) – If True the y axis is flipped.
threshold (float, default=0.0) – Minimal correlation abs value to be included in result. Must be in interval [0.0, 1.0].
-
points(type=None, diag=None)¶ Method defines correlation matrix layer drawn by points to the plot.
- Parameters
type ({‘upper’, ‘lower’, ‘full’}) – Type of matrix. Default - contextual.
diag (bool) – Determines whether to fill the main diagonal with values or not. Default - contextual.
- Returns
Correlation plot specification.
- Return type
corr_plot
-
labels(type=None, diag=None, map_size=None, color=None)¶ Method defines correlation matrix layer drawn with geom_text to the plot.
- Parameters
type ({‘upper’, ‘lower’, ‘full’}) – Type of matrix. Default - contextual.
diag (bool) – Determines whether to fill the main diagonal with values or not. Default - contextual.
map_size (bool) – If True, then absolute value of correlation is mapped to text size. If False - the text size is constant. Default - contextual.
color (str) – Set text color. Default - contextual.
- Returns
Correlation plot specification.
- Return type
corr_plot
-
tiles(type=None, diag=None)¶ Method defines correlation matrix layer drawn as square tiles to the plot.
- Parameters
type ({‘upper’, ‘lower’, ‘full’}) – Type of matrix. Default - contextual.
diag (bool) – Determines whether to fill the main diagonal with values or not. Default - contextual.
- Returns
Correlation plot specification.
- Return type
corr_plot
-
build() → lets_plot.plot.core.PlotSpec¶ This method creates PlotSpec object.
- Returns
Plot specification.
- Return type
PlotSpec
-
palette_gradient(low, mid, high)¶ Set scale_color_gradient2() and scale_fill_gradient() for corr plot.
- Parameters
low (str) – Color for low end of gradient (correlation -1).
mid (str) – Color for mid point (correlation 0).
high (str) – Color for high end of gradient (correlation 1).
- Returns
Correlation plot specification.
- Return type
corr_plot
-
palette_BrBG()¶ Set scale_color_brewer() with BrBG palette for corr plot.
- Returns
Correlation plot specification.
- Return type
corr_plot
-
palette_PiYG()¶ Set scale_color_brewer() with PiYG palette for corr plot.
- Returns
Correlation plot specification.
- Return type
corr_plot
-
palette_PRGn()¶ Set scale_color_brewer() with PRGn palette for corr plot.
- Returns
Correlation plot specification.
- Return type
corr_plot
-
palette_PuOr()¶ Set scale_color_brewer() with PuOr palette for corr plot.
- Returns
Correlation plot specification.
- Return type
corr_plot
-
palette_RdBu()¶ Set scale_color_brewer() with RdBu palette for corr plot.
- Returns
Correlation plot specification.
- Return type
corr_plot
-
palette_RdGy()¶ Set scale_color_brewer() with RdGy palette for corr plot.
- Returns
Correlation plot specification.
- Return type
corr_plot
-
palette_RdYlBu()¶ Set scale_color_brewer() with RdYlBu palette for corr plot.
- Returns
Correlation plot specification.
- Return type
corr_plot
-
palette_RdYlGn()¶ Set scale_color_brewer() with RdYlGn palette for corr plot.
- Returns
Correlation plot specification.
- Return type
corr_plot
-
palette_Spectral()¶ Set scale_color_brewer() with Spectral palette for corr plot.
- Returns
Correlation plot specification.
- Return type
corr_plot
-